﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace Tools
{
    internal class NavPanel<T> : FlowLayoutPanel
        where T : Control, INavControl<T>, new()
    {
        XmlNode node;
        public NavPanel(XmlNode node)
            : this()
        {
            this.node = node;
        }

        public NavPanel()
        {
            InitializeComponent();
        }

        protected override void InitLayout()
        {
            if (this.Parent != null)
            {
                this.Width = this.Parent.Width;
                this.Height = this.Parent.Height;
            }

            if (node != null)
            {
                T root = new T();
                root.NavXmlNode = node;
                foreach (T nav in root.NavButtons)
                {
                    this.Controls.Add(nav);
                }
            }

            base.InitLayout();
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            this.Top = 30;
            this.BackColor = System.Drawing.Color.Transparent;
            this.AutoScroll = true;
            this.Padding = new System.Windows.Forms.Padding(5);
            this.ResumeLayout(false);
        }
    }
}
